package com.xywy.beautyand.util;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.telephony.TelephonyManager;
import android.view.Display;
import android.view.WindowManager;

public class DeviceUtil {
	private static TelephonyManager telephonyManager;

	public static String getPhoneModel(Context context) {
		if (telephonyManager == null)
			telephonyManager = (TelephonyManager) context
					.getSystemService(Context.TELEPHONY_SERVICE);
		return android.os.Build.MODEL;
	}

	public static String getPhoneManufacturer(Context context) {
		if (telephonyManager == null)
			telephonyManager = (TelephonyManager) context
					.getSystemService(Context.TELEPHONY_SERVICE);
		return android.os.Build.MANUFACTURER;
	}

	public static String getPhoneDisplay(Context context) {
		Display display = ((WindowManager) context
				.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
		int width = display.getWidth();
		int height = display.getHeight();
		return width + "*" + height;
	}

	public static String getAppVersionCode(Context context) {

		PackageManager packageManager = context.getPackageManager();
		PackageInfo packInfo = null;
		try {
			packInfo = packageManager.getPackageInfo(context.getPackageName(),
					0);
		} catch (NameNotFoundException e) {
			e.printStackTrace();
			return null;
		}
		return packInfo.versionCode + "";
	}

	public static String getAppVersionName(Context context) {

		PackageManager packageManager = context.getPackageManager();
		PackageInfo packInfo = null;
		try {
			packInfo = packageManager.getPackageInfo(context.getPackageName(),
					0);
		} catch (NameNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		return packInfo.versionName + "";
	}

	public static int getDeviceWidth(Activity activity) {
		Display display = activity.getWindowManager().getDefaultDisplay();
		return display.getWidth();
	}

	public static int getDeviceHeight(Activity activity) {
		Display display = activity.getWindowManager().getDefaultDisplay();
		return display.getHeight();
	}

	public static int getNoticeBarHeight() {
		return Resources.getSystem().getDimensionPixelSize(
				Resources.getSystem().getIdentifier("status_bar_height",
						"dimen", "android"));
	}

}
